Returns the singleton instance of T
Syntax
| Visual Basic (Declaration) | |
|---|
Public Shared ReadOnly Property Instance As T |
| C# | |
|---|
public static T Instance {get;} |
Example
Library/Library.Test/TestFactories.cs
| C# | Copy Code |
|---|
try
{
GC.KeepAlive(Singleton<BadObject>.Instance);
Assert.Fail();
}
catch(ApplicationException ae)
{
Assert.AreEqual("BadObject", ae.GetBaseException().Message);
}
try
{
Singleton<BadObject>.Factory.Create();
Assert.Fail();
}
catch (ApplicationException ae)
{
Assert.AreEqual("BadObject", ae.GetBaseException().Message);
} |
| VB.NET | Copy Code |
|---|
Try
GC.KeepAlive(Singleton(Of BadObject).Instance)
Assert.Fail()
Catch ae As ApplicationException
Assert.AreEqual("BadObject", ae.GetBaseException().Message)
End Try
Try
Singleton(Of BadObject).Factory.Create()
Assert.Fail()
Catch ae As ApplicationException
Assert.AreEqual("BadObject", ae.GetBaseException().Message)
End Try |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also